#TOOLCHAIN = /usr/local/AVRMacPack/bin/

CC = $(TOOLCHAIN)avr-gcc
CFLAGS = -mmcu=atmega168 -Os
OBJCOPY = $(TOOLCHAIN)avr-objcopy
AVRDUDE = $(TOOLCHAIN)avrdude
PROGRAMMER = usbtiny
PARTNO = m168
FUSES =	-U efuse:w:0xf9:m \
	-U hfuse:w:0xd7:m \
	-U lfuse:w:0xe2:m 

APP = ledtro

default: all

all: $(APP).hex

OBJFILES := Peggy.o

Peggy.o : Peggy.c

$(APP).elf: $(OBJFILES)
	$(CC) $(CFLAGS) -lm -o $(APP).elf $(OBJFILES)

$(APP).hex: $(APP).elf
	 $(OBJCOPY) -O ihex $(APP).elf $(APP).hex

program: $(APP).hex
	$(AVRDUDE) -c $(PROGRAMMER) -p $(PARTNO) -V -e -U flash:w:$(APP).hex 

fuses:
	$(AVRDUDE) -c $(PROGRAMMER) -p $(PARTNO) $(FUSES)

clean:
	rm -f *.o *.hex *.elf
